(library (bool-utils)
  (export xor string->boolean)
  (import (except (rnrs base) map)
          (only (guile)
                lambda* λ)
          ;; GNU Guile batteries
          (ice-9 exceptions)
          ;; list procs
          (srfi srfi-1)))


(define xor
  (λ (a b)
    (or (and a (not b))
        (and (not a) b))))


(define string->boolean
  (lambda* (str
            #:key
            (fuzzy #f)
            (conversion-error-thunk
             (raise-exception
              (make-exception (make-non-continuable-error)
                              (make-exception-with-message "string not convertible to boolean")
                              (make-exception-with-irritants str)
                              (make-exception-with-origin 'string->boolean)))))
    "Convert string to boolean."
    (cond
     [(member str '("true" "#t")) #t]
     [(member str '("false" "#f")) #f]
     [fuzzy #f]
     [else
      (conversion-error-thunk)])))
